home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / qed / src / edit.c < prev    next >
C/C++ Source or Header  |  1998-10-29  |  52KB  |  2,243 lines

  1. #include <support.h>
  2. #include <time.h>
  3.  
  4. #include "global.h"
  5. #include "ausgabe.h"
  6. #include "av.h"
  7. #include "block.h"
  8. #include "clipbrd.h"
  9. #include "comm.h"
  10. #include "dd.h"
  11. #include "event.h"
  12. #include "error.h"
  13. #include "file.h"
  14. #include "find.h"
  15. #include "icon.h"
  16. #include "kurzel.h"
  17. #include "makro.h"
  18. #include "memory.h"
  19. #include "menu.h"
  20. #include "olga.h"
  21. #include "options.h"
  22. #include "poslist.h"
  23. #include "printer.h"
  24. #include "projekt.h"
  25. #include "rsc.h"
  26. #include "set.h"
  27. #include "sort.h"
  28. #include "tasten.h"
  29. #include "text.h"
  30. #include "umbruch.h"
  31. #include "window.h"
  32. #include "edit.h"
  33.  
  34. /* Exportierte Variablen ***************************************************/
  35. int    edit_type;
  36.  
  37. /****** DEFINES ************************************************************/
  38.  
  39. #define KIND    (NAME|INFO|CLOSER|FULLER|MOVER|SIZER|UPARROW|DNARROW|VSLIDE|LFARROW|RTARROW|HSLIDE|SMALLER)
  40. #define FLAGS    (WI_TEXT|WI_FONTSIZE|WI_REDRAW)
  41.  
  42. /* Anzahl der Änderungen in allen Texten bis zum restore_edit */
  43. #define MAX_CHG 30
  44.  
  45. #define TEMP_LINK 101
  46.  
  47. /****** TYPES **************************************************************/
  48.  
  49. typedef struct
  50. {
  51.     int    link;         /* Nummer von Text und Window */
  52.     int    c;         /* Art der Änderung */
  53.     long    y;         /* y-Position */
  54. } TCHANGE;
  55.  
  56. /* lokale Variablen ********************************************************/
  57. static SET            used_info;
  58. static int            chg_anz, find_erg, ascii_wert;
  59. static TCHANGE     chg[MAX_CHG];
  60. static SET            chg_links;
  61. static POSENTRY    *lastpos_list = NULL;
  62.  
  63. /* lokale Prototypen *******************************************************/
  64.  
  65. static void     e_icon_exist    (int icon, SET actions);
  66. static bool     e_icon_test        (int icon, int action);
  67. static int        e_icon_edit        (int icon, int action);
  68. static bool     e_icon_drag        (int icon, int source);
  69. static void     wi_draw            (WINDOWP window, GRECT *d);
  70. static void     wi_click         (WINDOWP window, int m_x, int m_y, int bstate, int kstate, int breturn);
  71. static bool     wi_key            (WINDOWP window, int kstate, int kreturn);
  72. static void     wi_top            (WINDOWP window);
  73. static void        wi_iconify        (WINDOWP window);
  74. static void        wi_uniconify    (WINDOWP window);
  75. static void     destruct         (int icon);
  76.  
  77. static void     lz2tab            (TEXTP t_ptr);
  78. static void     tab2lz            (TEXTP t_ptr);
  79. static void     goto_line        (TEXTP t_ptr, int x, long y);
  80. static void     make_undo        (TEXTP t_ptr);
  81. static void     print_edit        (TEXTP t_ptr);
  82. static bool     open_edit        (int icon);
  83. static void     crt_edit         (WINDOWP window);
  84. static int      crt_new_text    (char *filename, bool bin);
  85.  
  86. /***************************************************************************/
  87.  
  88. static int col_lz2tab(ZEILEP col, char *t, int tab_size)
  89. {
  90.     char    *str, c;
  91.     int    i, tabH, lz, len;
  92.     bool    changes;
  93.  
  94.     str = TEXT(col);
  95.     changes = FALSE;
  96.     tabH = tab_size;
  97.     lz = 0;
  98.     len = 0;
  99.     for (i=col->len; (--i)>=0; )
  100.     {
  101.         c = *str++;
  102.         if (c==' ')
  103.         {
  104.             if ((--tabH)==0)
  105.             {
  106.                 if (lz>0)            /* Leerzeichen ersetzen */
  107.                 {
  108.                     c = '\t';
  109.                     t -= lz;
  110.                     len -= lz;
  111.                     changes = TRUE;
  112.                 }
  113.                 tabH = tab_size;
  114.                 lz = 0;
  115.             }
  116.             else
  117.                 lz++;
  118.         }
  119.         else
  120.         {
  121.             lz = 0;
  122.             if ((--tabH)==0) tabH = tab_size;
  123.         }
  124.         *t++ = c;
  125.         len++;
  126.     }
  127.     *t = EOS;
  128.     if (changes)
  129.         return (len);
  130.     return (-1);
  131. }
  132.  
  133. static void lz2tab(TEXTP t_ptr)
  134. {
  135.     ZEILEP     lauf;
  136.     int        x, i, tabsize;
  137.     char        str[MAX_LINE_LEN + 1];
  138.  
  139.     graf_mouse(HOURGLASS, NULL);
  140.     tabsize = t_ptr->loc_opt->tabsize;
  141.     x = bild_pos(t_ptr->xpos,t_ptr->cursor_line,TRUE,tabsize);
  142.     lauf = FIRST(&t_ptr->text);
  143.     while (!IS_TAIL(lauf))
  144.     {
  145.         i = col_lz2tab(lauf, str, tabsize);
  146.         if (i != -1)                                    /* Zeile verändert */
  147.         {
  148.             REALLOC (&lauf, 0, i-lauf->len);
  149.             memcpy(TEXT(lauf), str, (int) strlen(str));
  150.             t_ptr->moved++;
  151.         }
  152.         NEXT(lauf);
  153.     }
  154.     t_ptr->cursor_line = get_line(&t_ptr->text,t_ptr->ypos);
  155.     t_ptr->xpos = inter_pos(x,t_ptr->cursor_line,TRUE,tabsize);
  156.     make_chg(t_ptr->link,POS_CHANGE,0);     /* immer: Damit Infozeile einen '*' bekommt */
  157.     restore_edit();
  158.     graf_mouse(ARROW, NULL);
  159. }
  160.  
  161. static int col_tab2lz(ZEILEP col, char *t, int tab_size)
  162. {
  163.     bool    with_tab = FALSE;
  164.     int    tabH, len, i;
  165.     char    *str, c;
  166.  
  167.     str = TEXT(col);
  168.     tabH = tab_size;
  169.     for (i = col->len,len = 0; (--i) >= 0 && (len < (MAX_LINE_LEN+1)); )
  170.     {
  171.         c = *str++;
  172.         if (c == '\t')
  173.         {
  174.             with_tab = TRUE;
  175.             len += tabH;
  176.             if (len > (MAX_LINE_LEN+1))
  177.                 tabH -= (len - (MAX_LINE_LEN+1));
  178.             do
  179.             {
  180.                 *t++ = ' ';
  181.             }
  182.             while (--tabH);
  183.             tabH = tab_size;
  184.         }
  185.         else
  186.         {
  187.             *t++ = c;
  188.             if ((--tabH)==0)
  189.                 tabH = tab_size;
  190.             len++;
  191.         }
  192.     }
  193.     *t = EOS;
  194.     if (with_tab)
  195.         return(len);
  196.     else
  197.         return(-1);
  198. }
  199.  
  200. static void tab2lz(TEXTP t_ptr)
  201. {
  202.     ZEILEP     lauf;
  203.     int        i, x, tabsize;
  204.     char        str[MAX_LINE_LEN + 1];
  205.  
  206.     graf_mouse(HOURGLASS, NULL);
  207.     tabsize = t_ptr->loc_opt->tabsize;
  208.     x = bild_pos(t_ptr->xpos,t_ptr->cursor_line,TRUE,tabsize);
  209.     lauf = FIRST(&t_ptr->text);
  210.     while (!IS_TAIL(lauf))
  211.     {
  212.         i = col_tab2lz (lauf,str,tabsize);
  213.         if (i != -1)                                    /* Zeile verändert */
  214.         {
  215.             REALLOC (&lauf, 0, i-lauf->len);
  216.             memcpy(TEXT(lauf), str, (int)strlen(str));
  217.             t_ptr->moved++;
  218.         }
  219.         NEXT(lauf);
  220.     }
  221.     t_ptr->cursor_line = get_line(&t_ptr->text,t_ptr->ypos);
  222.     t_ptr->xpos = inter_pos(x,t_ptr->cursor_line,TRUE,tabsize);
  223.     make_chg(t_ptr->link,POS_CHANGE,0);     /* immer: Damit Infozeile einen '*' bekommt */
  224.     restore_edit();
  225.     graf_mouse(ARROW, NULL);
  226. }
  227.  
  228. static void goto_line(TEXTP t_ptr, int x, long y)
  229. {
  230.     if (x < 0)
  231.         x = 0;
  232.     if (y < 0)
  233.         y = 0;
  234.     if (y >= t_ptr->text.lines)
  235.         y = t_ptr->text.lines - 1L;
  236.     t_ptr->cursor_line = get_line(&t_ptr->text, y);
  237.     t_ptr->ypos = y;
  238.     t_ptr->xpos = inter_pos(x,t_ptr->cursor_line,t_ptr->loc_opt->tab,t_ptr->loc_opt->tabsize);
  239.     make_chg(t_ptr->link,POS_CHANGE, 0);
  240. }
  241.  
  242. static void make_undo(TEXTP t_ptr)
  243. {
  244.     int undo;
  245.  
  246.     undo = get_undo();
  247.     if (undo == NO_UNDO) 
  248.         return;
  249.  
  250.     /*
  251.      * Vorher an undo_pos springen
  252.      * Weil sonst u.U. restore zu schwierig
  253.      * Wird auch von do_undo_col vorausgesetzt
  254.     */
  255.     t_ptr->cursor_line = get_line(&t_ptr->text,undo_y);
  256.     t_ptr->ypos = undo_y;
  257.     t_ptr->xpos = 0;
  258.     make_chg(t_ptr->link,POS_CHANGE,0);
  259.     restore_edit();
  260.  
  261.     do
  262.     {
  263.         if (undo == COL_ANDERS)
  264.         {
  265.             do_undo_col(t_ptr,undo);
  266.             restore_edit();
  267.         }
  268.         else
  269.         {
  270.             blk_undo(t_ptr,undo);
  271.             restore_edit();
  272.         }
  273.         undo = get_undo();
  274.     }
  275.     while (undo != NO_UNDO);
  276. }
  277.  
  278. /***************************************************************************/
  279.  
  280. static void do_absatz(WINDOWP window)
  281. {
  282.     if (window->flags & WI_TEXT)                     /* Text-Fenster */
  283.     {
  284.         TEXTP    t_ptr = get_text(window->handle);
  285.         
  286.         make_absatz(t_ptr);
  287.         get_longestline(t_ptr);
  288.         if (window->doc.w != t_ptr->max_line->exp_len)
  289.         {
  290.             window->doc.w = t_ptr->max_line->exp_len;
  291.             set_sliders(window, HORIZONTAL, SLPOS+SLSIZE);
  292.         }    
  293.         redraw_window(window, &window->work);
  294.     }
  295. }
  296.  
  297.  
  298. /*
  299.  * Es wurde Zeilenumbruch ein oder ausgeschaltet und/oder Tab geändert 
  300. */
  301. void absatz_edit(void)
  302. {
  303.     do_all_window(CLASS_EDIT, do_absatz);
  304. }
  305.  
  306.  
  307. /***************************************************************************/
  308.  
  309. static void chg_edit_name(int icon)
  310. {
  311.     WINDOWP    window = get_window(icon);
  312.     TEXTP     t_ptr = get_text(icon);
  313.  
  314.     set_wtitle(window, t_ptr->filename);
  315. }
  316.  
  317. /***************************************************************************/
  318. /* Anlegen einer neuen Textdatei                                                         */
  319. /***************************************************************************/
  320.  
  321. int new_edit(void)
  322. {
  323.     int    icon;
  324.     TEXTP t_ptr;
  325.  
  326.     icon = crt_new_text("", FALSE);
  327.     if (icon < 0)
  328.     {
  329.         note(1, 0, NOTEXT);
  330.         return -1;
  331.     }
  332.     t_ptr = get_text(icon);
  333.     if (t_ptr->loc_opt->umbrechen)
  334.         make_absatz(t_ptr);
  335.     if (do_icon(icon,DO_OPEN) < 0)
  336.     {
  337.         note(1, 0, NOWINDOW);
  338.         icon_edit(icon, DO_DELETE);
  339.         icon = -3;
  340.     }
  341.     return icon;
  342. } /* new_edit */
  343.  
  344. /***************************************************************************/
  345.  
  346. int load_edit(char *name, bool bin)
  347. /* return: <=0 wurde nicht geladen */
  348. /*           =0    weitere Texte versuchen sinnvoll */
  349. /*           <0    weiter Texte versuchen nicht sinnvoll */
  350. {
  351.     WINDOWP     window;
  352.     TEXTP     t_ptr;
  353.     FILENAME    datei;
  354.     PATH        path;
  355.     int        err, icon;
  356.  
  357.     store_path(name);
  358.  
  359.     if (!bin && is_bin_name(name))
  360.         bin = TRUE;
  361.  
  362.     split_filename(name, path, datei);
  363.     if ((icon = text_still_loaded(name)) > 0)            /* schon geladen */
  364.     {
  365.         if (do_icon(icon, DO_OPEN) < 0)                    /* nur Fenster auf */
  366.             note(1, 0, NOWINDOW);
  367.         return icon;
  368.     }
  369.  
  370.     icon = crt_new_text(name, bin);                        /* neuen Text anlegen */
  371.     if (icon < 0)
  372.     {
  373.         note(1, 0, NOTEXT);
  374.         return -1;                                                /* hat keinen Zweck mehr */
  375.     }
  376.     t_ptr = get_text(icon);
  377.     
  378.     if ((err = load(t_ptr, TRUE)) == -33)                /* File not Found */
  379.     {
  380.         if (path_exists(path))
  381.         {
  382.             if (snote(1, 2, NEWTEXT, datei) == 2)        /* neue Datei anlegen */
  383.             {
  384.                 icon_edit(icon, DO_DELETE);
  385.                 return 0;                                        /* naechsten versuche */
  386.             }
  387.         }
  388.         else
  389.         {
  390.             snote(1, 0, READERR, datei);
  391.             icon_edit(icon, DO_DELETE);
  392.             return 0;                                            /* naechsten versuchen */
  393.         }
  394.     }
  395.     else if (err)                                                /* anderer Fehler */
  396.     {
  397.         snote(1, 0, READERR, datei);
  398.         icon_edit(icon, DO_DELETE);
  399.         return 0;
  400.     }
  401.     if (t_ptr->loc_opt->umbrechen)
  402.     {
  403.         make_absatz(t_ptr);
  404.         if (t_ptr->loc_opt->format_by_load)
  405.             total_format(t_ptr);
  406.     }
  407.     window = get_window(icon);
  408.     window->doc.x = 0;
  409.     window->doc.y = 0;
  410.     window->doc.w = get_longestline(t_ptr);
  411.     window->doc.h = t_ptr->text.lines;
  412.     if (do_icon(icon, DO_OPEN) < 0)
  413.     {
  414.         note(1, 0, NOWINDOW);
  415.         icon_edit(icon, DO_DELETE);
  416.         icon = -2;
  417.     }
  418.     if (t_ptr->moved)                                         
  419.     {
  420.         if (t_ptr->loc_opt->umbrechen)                    /* format_by_load */
  421.             set_info(t_ptr, rsc_string(UMBRUCHSTR));
  422.         else                                                        /*    Nullbytes */
  423.         {
  424.             make_chg(t_ptr->link,TOTAL_CHANGE,0);
  425.             set_info(t_ptr, rsc_string(NULLBYTESTR));
  426.         }
  427.         change_window(window, t_ptr->filename, TRUE);
  428.         restore_edit();
  429.         Bconout(2, 7);
  430.     }
  431.  
  432.     if (find_poslist(lastpos_list, name, &desire_x, &desire_y) != NULL)
  433.         icon_edit(icon, DO_GOTO);
  434.     else
  435.         insert_poslist(&lastpos_list, name, 0, 0);
  436.  
  437.     return icon;
  438. }
  439.  
  440. /***************************************************************************/
  441.  
  442. static void print_edit (TEXTP t_ptr)
  443. {
  444.     FILENAME name;
  445.     bool        print_block;
  446.     
  447.     if (t_ptr->namenlos)
  448.         strcpy(name, t_ptr->filename);
  449.     else
  450.         file_name(t_ptr->filename, name, FALSE);
  451.     print_block = t_ptr->block;
  452.     if (prn_start_dial(&print_block))
  453.     {
  454.         if (print_block)
  455.             blk_drucken(name, t_ptr);
  456.         else
  457.             txt_drucken(name, t_ptr);
  458.     }
  459. } /* print_edit */
  460.  
  461.  
  462. void close_edit(char *mask, int flag)
  463. {
  464.     int i, min;
  465.     
  466.     min = setmin(used_info);
  467.     for (i = setmax(used_info); i >= min; i--)
  468.     {
  469.         if (setin(used_info, i))
  470.         {
  471.             TEXTP t_ptr = get_text(i);
  472.  
  473.             if (filematch(t_ptr->filename, mask, t_ptr->filesys))
  474.             {
  475. debug("  match: name= %s, fs= %d -- OK\n", t_ptr->filename, t_ptr->filesys);
  476.                 switch (flag)
  477.                 {
  478.                     case 0 :                            /* sichern ohne schließen */
  479.                         if (t_ptr->moved)            /* nur wenn nötig! */
  480.                             do_icon(i, DO_SAVE);
  481.                         break;
  482.  
  483.                     case 1 :                            /* sichern und schließen */
  484.                         do_icon(i, DO_DELETE);
  485.                         break;
  486.  
  487.                     case 2 :                            /* schließen ohne sichern */
  488.                         t_ptr->moved = 0;
  489.                         do_icon(i, DO_DELETE);
  490.                         break;
  491.  
  492.                     default:
  493.                         debug("close_edit: Unknown SE_CLOSE Flag %d\n", flag);
  494.                         break;
  495.                 }
  496.             }
  497. else
  498. debug("  match: name= %s, fs= %d -- failed\n", t_ptr->filename, t_ptr->filesys);
  499.         }
  500.     }
  501. }
  502.  
  503.  
  504. static bool delete_edit(int icon, TEXTP t_ptr)
  505. {
  506.     int    antw;
  507.     FILENAME    name;
  508.  
  509.     if (t_ptr->moved != 0)
  510.     {
  511.         if (quick_close)
  512.             antw = 1;
  513.         else
  514.         {
  515.             if (t_ptr->namenlos)
  516.                 strcpy(name, t_ptr->filename);
  517.             else
  518.                 file_name(t_ptr->filename, name, FALSE);
  519.             antw = snote(1, 3, MOVED, name);
  520.         }
  521.         if (antw == 1)
  522.         {
  523.             if (do_icon(icon,DO_SAVE) < 0)
  524.                 return (FALSE);
  525.         }
  526.         if (antw == 3)
  527.             return(FALSE);
  528.     }
  529.     return (TRUE);
  530. }
  531.  
  532. /***************************************************************************/
  533. /* Fenster angeclickt                                                                        */
  534. /***************************************************************************/
  535. static void set_cursor(WINDOWP window, int mx, int my)
  536. {
  537.     TEXTP     t_ptr = get_text(window->handle);
  538.     int        x;
  539.     long        y;
  540.     ZEILEP    col;
  541.  
  542.     y = (my - window->work.g_y);
  543.     if (y < 0)
  544.         y -= font_hcell;     /* wg. Rundung */
  545.     y /= font_hcell;
  546.     y += window->doc.y;
  547.     if (y >= t_ptr->text.lines)
  548.         y = t_ptr->text.lines-1;
  549.     else if (y < 0)
  550.         y = 0;
  551.     col = get_line(&t_ptr->text, y);
  552.  
  553.     t_ptr->ypos = y;
  554.     t_ptr->cursor_line = col;
  555.     if (font_prop)
  556.     {
  557.         int    i, x_soll, s, e, xl; 
  558.  
  559.         x_soll = (mx - window->work.g_x) + ((int) window->doc.x * font_wcell);
  560.  
  561.         /* Zur groben Positionierung machen wir "Halbierungs-Algorithmus" */
  562.         s = 0;
  563.         e = col->len;
  564.         xl = -1;
  565.         while (TRUE)
  566.         {
  567.             x = s + ((e - s) / 2);
  568.             if (x == xl)
  569.                 break;
  570.             t_ptr->xpos = x;
  571.             i = cursor_xpos(t_ptr, t_ptr->xpos);
  572.             if (i > x_soll)
  573.                 e = x;            /* in linker Hälfte */
  574.             else
  575.                 s = x;            /* in rechter Hälfte */
  576.             xl = x;                
  577.         }
  578.         /* jetzt Fein-Positionierung zeichenweise heranbewegen */
  579.         for (x = s; x <= e; x++)
  580.         {
  581.             t_ptr->xpos = x;
  582.             i = cursor_xpos(t_ptr, t_ptr->xpos);
  583.             if (i > x_soll) 
  584.                 break;
  585.         }
  586.         x--;
  587.     }
  588.     else
  589.     {
  590.         x = mx - window->work.g_x;
  591.         if (x > 0)
  592.         {
  593.             x /= font_wcell;
  594.             x += (int) window->doc.x;
  595.         }
  596.         else if (window->doc.x>0)
  597.             x = (int) window->doc.x-1;
  598.         else
  599.             x = 0;
  600.         x = inter_pos(x,col,t_ptr->loc_opt->tab,t_ptr->loc_opt->tabsize);
  601.     }
  602.     t_ptr->xpos = x;
  603.  
  604.     y -= window->doc.y;
  605.     if (y > 0)
  606.     {
  607.         if (y > window->w_height)
  608.             make_chg(t_ptr->link,MOVE_UP, y-window->w_height);
  609.     }
  610.     else
  611.         make_chg(t_ptr->link,MOVE_DOWN, -y);
  612.     make_chg(t_ptr->link,POS_CHANGE, 0);
  613. }
  614.  
  615. #define LINE_MODE        1
  616. #define WORD_MODE        2
  617. #define KEY_MODE        3
  618. #define BRACE_MODE    4
  619.  
  620. static void wi_click(WINDOWP window, int m_x, int m_y, int bstate, int kstate, int breturn)
  621. {
  622.     int        event, mode, kreturn;
  623.     TEXTP     t_ptr = get_text(window->handle);
  624.     GRECT        *s = &window->work;
  625.     
  626.     /* Infomeldung löschen */
  627.     clear_info(t_ptr);
  628.  
  629.     if (bstate & 2)                         /* Rechtsclick */
  630.     {
  631.         if (strlen(error[0]) > 0)
  632.         {
  633.             blk_demark(t_ptr);
  634.             set_cursor(window, m_x, m_y);
  635.             restore_edit();
  636.             handle_error(t_ptr);
  637.         }
  638.         return;                                /* und wech... */
  639.     }
  640.  
  641.     if (!inside(m_x, m_y, s))
  642.         return;
  643.     t_ptr->blk_mark_mode = FALSE;
  644.     unclick_window();
  645.     if (breturn == 2)                        /* Doppelklick */
  646.     {
  647.         blk_demark(t_ptr);
  648.         set_cursor(window, m_x, m_y);
  649.         restore_edit();
  650.         if (kstate & (K_RSHIFT|K_LSHIFT) ||                /* Ganze Zeile markieren */
  651.              t_ptr->xpos==t_ptr->cursor_line->len)
  652.         {
  653.             t_ptr->xpos = 0;
  654.             blk_mark(t_ptr, 0);
  655.             if (IS_LAST(t_ptr->cursor_line))
  656.                 t_ptr->xpos = t_ptr->cursor_line->len;
  657.             else
  658.             {
  659.                 NEXT(t_ptr->cursor_line);
  660.                 t_ptr->ypos++;
  661.             }
  662.             blk_mark(t_ptr, 1);
  663.             restore_edit();
  664.             mode = LINE_MODE;
  665.         }
  666.         else if (blk_mark_brace(t_ptr))                            /* Klammer-Selektion */
  667.         {
  668.             restore_edit();
  669.             mode = BRACE_MODE;
  670.         }
  671.         else                                                                /* wortweise */
  672.         {
  673.             blk_mark_word(t_ptr);
  674.             mode = WORD_MODE;
  675.         }
  676.     }
  677.     else                                                                    /* Einfachklick */
  678.     {
  679.         if (kstate & (K_RSHIFT|K_LSHIFT))
  680.         {
  681.             if (!t_ptr->block)
  682.                 blk_mark(t_ptr,0);                                    /* Anfang = alte Cursorpos */
  683.             set_cursor(window, m_x, m_y);
  684.             blk_mark(t_ptr, 1);
  685.             restore_edit();
  686.         }
  687.         else
  688.         {
  689. #if 0
  690.             graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  691.             if (t_ptr->block && bstate & 1)                        /* immernoch gedrückt */
  692.             {
  693. extern int drag_box(int x, int y, int w, int h, int *m_x, int *m_y, int *bstate, int *kstate);
  694.  
  695.                 debug("ping\n");
  696.             }
  697.             else
  698. #endif
  699.             {
  700.                 blk_demark(t_ptr);
  701.                 set_cursor(window, m_x, m_y);
  702.                 blk_mark(t_ptr, 0);
  703.                 restore_edit();
  704.             }
  705.         }
  706.         mode = KEY_MODE;
  707.     }
  708.     graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  709.     if (bstate & 1)                                                    /* immernoch gedrückt */
  710.     {
  711.         graf_mouse(POINT_HAND, NULL);
  712.         wind_update(BEG_MCTRL);                        /* Mauskontrolle übernehmen */
  713.         while(TRUE)
  714.         {
  715.             event = evnt_multi((MU_BUTTON | MU_M1 | MU_M2),
  716.                                       1, 0x01, 0x00,
  717.                                       TRUE, m_x, m_y, 1, 1,
  718.                                       TRUE, s->g_x, s->g_y, s->g_w, s->g_h,
  719.                                       NULL, 0L,
  720.                                       &m_x, &m_y, &bstate, &kstate, &kreturn, &breturn);
  721.  
  722.             if (event & MU_BUTTON) 
  723.                 break;
  724.             if (event & (MU_M1 | MU_M2))
  725.             {
  726.                 set_cursor(window, m_x, m_y);
  727.                 if (mode == WORD_MODE)
  728.                 {
  729.                     long    y;
  730.                     int    x, pos,len;
  731.                     char    *str;
  732.  
  733.                     pos = t_ptr->xpos;
  734.                     str = TEXT(t_ptr->cursor_line) + pos;
  735.                     len = t_ptr->cursor_line->len;
  736.                     get_blk_mark(t_ptr, &y, &x);
  737.                     if (t_ptr->ypos > y || t_ptr->xpos > x)         /* nach rechts */
  738.                     {
  739.                         while(pos<=len && setin(t_ptr->loc_opt->wort_set,*str))
  740.                         {
  741.                             pos++;
  742.                             str++;
  743.                         }
  744.                     }
  745.                     else                                                    /* nach links */
  746.                     {
  747.                         while(pos>=0 && setin(t_ptr->loc_opt->wort_set,*str))
  748.                         {
  749.                             pos--;
  750.                             str--;
  751.                         }
  752.                         str++; pos++;
  753.                     }
  754.                     t_ptr->xpos = pos;
  755.                 }
  756.                 else if (mode == LINE_MODE)
  757.                 {
  758.                     long    y;
  759.                     int    x;
  760.  
  761.                     get_blk_mark(t_ptr, &y, &x);
  762.                     t_ptr->xpos = 0;
  763.                     if (y == t_ptr->ypos && !IS_LAST(t_ptr->cursor_line))
  764.                     {
  765.                         NEXT(t_ptr->cursor_line);
  766.                         t_ptr->ypos++;
  767.                     }
  768.                 }
  769.                 blk_mark(t_ptr, 1);
  770.                 restore_edit();
  771.             }
  772.         }
  773.         wind_update(END_MCTRL);                        /* Mauskontrolle wieder abgeben */
  774.         graf_mouse(ARROW, NULL);
  775.     }
  776. }
  777.  
  778.  
  779. static bool wi_key (WINDOWP window, int kstate, int kreturn)
  780. {
  781.     TEXTP t_ptr = get_text(window->handle);
  782.  
  783.     /* Infomeldung löschen */
  784.     clear_info(t_ptr);
  785.  
  786.     if (edit_key(t_ptr, window, kstate, kreturn))
  787.     {
  788.         restore_edit();
  789.         return TRUE;
  790.     }
  791.     return FALSE;
  792. }
  793.  
  794.  
  795. static void wi_draw(WINDOWP window, GRECT *d)
  796. {
  797.     TEXTP t_ptr = get_text(window->handle);
  798.  
  799.     set_clip(TRUE, d);
  800.     if (d->g_x == window->work.g_x && d->g_w == window->work.g_w)
  801.     {
  802.         if (d->g_y == window->work.g_y + window->work.g_h - window->yfac &&
  803.              d->g_h == window->yfac)
  804.         {
  805.             /* Letzte Zeile */
  806.             line_out(window, t_ptr, window->w_height - 1);
  807.         }
  808.         else if (d->g_y == window->work.g_y && d->g_h == window->yfac)
  809.         {
  810.             /* Erste Zeile */
  811.             line_out(window, t_ptr, 0);
  812.         }
  813.         else
  814.             bild_out(window, t_ptr);
  815.     }
  816.     else
  817.         bild_out(window,t_ptr);
  818. }
  819.  
  820.  
  821. static void wi_top(WINDOWP window)
  822. {
  823.     /* Kürzel/Schreibschutz ändern */
  824.     do_icon(window->handle, DO_UPDATE);
  825. }
  826.  
  827. static    void wi_iconify(WINDOWP window)
  828. {
  829.     TEXTP     t_ptr = get_text(window->handle);
  830.     FILENAME    short_name;
  831.  
  832.     make_shortpath(t_ptr->filename, short_name, 8);
  833.     set_wtitle(window, short_name);
  834. }
  835.  
  836. static    void wi_uniconify(WINDOWP window)
  837. {
  838.     TEXTP t_ptr = get_text(window->handle);
  839.  
  840.     set_wtitle(window, t_ptr->filename);
  841. }
  842.  
  843. /***************************************************************************/
  844. /* Operation vorhanden ?                                                                    */
  845. /***************************************************************************/
  846.  
  847. static void e_icon_exist(int icon, SET actions)
  848. {
  849.     TEXTP        t_ptr = get_text(icon);
  850.     WINDOWP    window = get_window(icon);
  851.  
  852.     setclr(actions);
  853.  
  854.     if ((window->flags & WI_ICONIFIED) || (window->flags & WI_SHADED))
  855.     {
  856.         /* Einzige mögliche Aktion: */
  857.         setincl(actions, DO_DELETE);
  858.         return;
  859.     }
  860.  
  861.     if (any_undo())
  862.         setincl(actions, DO_UNDO);
  863.     if (t_ptr->block)
  864.     {
  865.         setincl(actions, DO_CUT);
  866.         setincl(actions, DO_COPY);
  867.         setincl(actions, DO_LEFT);
  868.         setincl(actions, DO_RIGHT);
  869.         setincl(actions, DO_BIG2SMALL);
  870.         setincl(actions, DO_SMALL2BIG);
  871.         setincl(actions, DO_CHNG_SMBG);
  872.         setincl(actions, DO_CAPS);
  873.         setincl(actions, DO_SORT);
  874.     }
  875.     else
  876.     {
  877.         setincl(actions, DO_LINECOPY);
  878.         setincl(actions, DO_SWAPCHAR);
  879.     }
  880.     if (t_ptr->loc_opt->tab)
  881.     {
  882.         setincl(actions, DO_TAB2LZ);
  883.         setincl(actions, DO_LZ2TAB);
  884.     }
  885.     if (t_ptr->loc_opt->umbrechen)
  886.         setincl(actions, DO_FORMAT);
  887.     else
  888.         setincl(actions, DO_STRIPLINES);
  889.     if (window->flags & WI_OPEN)
  890.         setincl(actions, DO_CLOSE);
  891.     setincl(actions, DO_DELETE);
  892.     setincl(actions, DO_PASTE);
  893.     setincl(actions, DO_SELALL);
  894.     setincl(actions, DO_OPEN);
  895.     setincl(actions, DO_INFO);
  896.     setincl(actions, DO_HELP);
  897.     setincl(actions, DO_PRINT);
  898.     if (!t_ptr->namenlos)
  899.         setincl(actions,DO_ABAND);
  900.     setincl(actions, DO_SAVE);
  901.     setincl(actions, DO_SAVENEW);
  902.     setincl(actions, DO_FIND);
  903.     setincl(actions, DO_FINDNEXT);
  904.     setincl(actions, DO_GOTO);
  905.     setincl(actions, DO_ADD);
  906.     setincl(actions, DO_UPDATE);
  907.     setincl(actions, DO_ZEICHTAB);
  908.     setincl(actions, DO_UMLAUT);
  909.     if (t_ptr->moved)
  910.         setincl(actions, DO_AUTOSAVE);
  911.     setincl(actions, DO_FEHLER);
  912.     if ((t_ptr->ypos - window->doc.y) > 0)
  913.         setincl(actions, DO_TOPLINE);
  914. }
  915.  
  916. /***************************************************************************/
  917. /* Operation testen                                                                            */
  918. /***************************************************************************/
  919.  
  920. static bool e_icon_test(int icon, int action)
  921. {
  922.     bool    erg;
  923.     TEXTP     t_ptr = get_text(icon);
  924.     FILENAME    name;
  925.  
  926.     switch(action)
  927.     {
  928.         case DO_UNDO    :
  929.             erg = any_undo();
  930.             break;
  931.         case DO_CUT     :
  932.             erg = t_ptr->block;
  933.              break;
  934.         case DO_COPY    :
  935.             erg = t_ptr->block;
  936.             break;
  937.         case DO_LINECOPY:
  938.             erg = !(t_ptr->block);
  939.             break;
  940.         case DO_PASTE    :
  941.             erg = TRUE;
  942.             break;
  943.         case DO_SELALL :
  944.             erg = TRUE;
  945.             break;
  946.         case DO_CLOSE    :
  947.         case DO_DELETE    :
  948.             erg = delete_edit(icon, t_ptr);
  949.             break;
  950.         case DO_OPEN    :
  951.             erg = TRUE;
  952.             break;
  953.         case DO_INFO    :
  954.             erg = TRUE;
  955.             break;
  956.         case DO_HELP    :
  957.             erg = TRUE;
  958.             break;
  959.         case DO_LEFT    :
  960.         case DO_RIGHT    :
  961.         case DO_BIG2SMALL    :
  962.         case DO_SMALL2BIG    :
  963.         case DO_CHNG_SMBG    :
  964.         case DO_CAPS        :
  965.         case DO_SORT         :
  966.             erg = t_ptr->block;
  967.             break;
  968.         case DO_FORMAT :
  969.             erg = t_ptr->loc_opt->umbrechen;
  970.             break;
  971.         case DO_PRINT    :
  972.             erg = TRUE;
  973.             break;
  974.         case DO_ABAND    :
  975.             if (t_ptr->namenlos)
  976.                 erg = FALSE;
  977.             else
  978.             {
  979.                 erg = TRUE;
  980.                 if (!ist_leer(&t_ptr->text) && t_ptr->moved!=0)
  981.                 {
  982.                     if (t_ptr->namenlos)
  983.                         strcpy(name, t_ptr->filename);
  984.                     else
  985.                         file_name(t_ptr->filename, name, FALSE);
  986.                     erg = (snote(1, 2, ABANDON, name) == 1);
  987.                 }
  988.             }
  989.             break;
  990.         case DO_SAVE    :
  991.             erg = TRUE;
  992.             break;
  993.         case DO_SAVENEW:
  994.             erg = TRUE;
  995.             break;
  996.         case DO_FIND :
  997.             if (t_ptr->block && shift_pressed())
  998.                 erg = TRUE;
  999.             else
  1000.             {
  1001.                 find_erg = replace_dial();
  1002.                 erg = (find_erg!=0);
  1003.             }
  1004.             break;
  1005.         case DO_FINDNEXT:
  1006.             erg = TRUE;
  1007.             break;
  1008.         case DO_ADD     :
  1009.             erg = TRUE;
  1010.             break;
  1011.         case DO_GOTO    :
  1012.             erg = goto_line_dial();
  1013.             break;
  1014.         case DO_STRIPLINES:
  1015.             erg = !t_ptr->loc_opt->umbrechen;
  1016.             break;
  1017.         case DO_TAB2LZ :
  1018.             erg = t_ptr->loc_opt->tab;
  1019.             break;
  1020.         case DO_LZ2TAB :
  1021.             erg = t_ptr->loc_opt->tab;
  1022.             break;
  1023.         case DO_UPDATE    :
  1024.             erg = TRUE;
  1025.             break;
  1026.         case DO_ZEICHTAB:
  1027.             ascii_wert = ascii_table(font_id, 13);
  1028.             erg = (ascii_wert != -1);
  1029.             break;
  1030.         case DO_UMLAUT:
  1031.             erg = umlaut_dial();
  1032.             break;
  1033.         case DO_SWAPCHAR:
  1034.             erg = !t_ptr->block;
  1035.             break;
  1036.         case DO_AUTOSAVE :
  1037.             if (as_text && t_ptr->moved)
  1038.             {
  1039.                 long    min;
  1040.                 int    btn;
  1041.  
  1042.                 min = (int)((time(NULL) - t_ptr->asave) / 60L);
  1043.                 if (min >= as_text_min)
  1044.                 {
  1045.                     if (as_text_ask)                /* Nachfrage ? */
  1046.                     {
  1047.                         FILENAME        name;
  1048.  
  1049.                         if (t_ptr->namenlos)
  1050.                             strcpy(name, t_ptr->filename);
  1051.                         else
  1052.                             file_name(t_ptr->filename, name, FALSE);
  1053.                         Bconout(2, 7);
  1054.                         btn = snote(2, 3, ASAVEASK, name);
  1055.                         if (btn == 1)
  1056.                             as_text = FALSE;
  1057.                     }
  1058.                     else
  1059.                         btn = 2;
  1060.  
  1061.                     t_ptr->asave = time(NULL);
  1062.                     erg = (btn == 2);
  1063.                 }
  1064.                 else
  1065.                     erg = FALSE;
  1066.             }
  1067.             else
  1068.             {
  1069.                 t_ptr->asave = time(NULL);
  1070.                 erg = FALSE;
  1071.             }
  1072.             break;
  1073.         case DO_FEHLER :
  1074.             erg = TRUE;
  1075.             break;
  1076.         case DO_TOPLINE :
  1077.             erg = TRUE;
  1078.             break;
  1079.         default    :
  1080.             erg = FALSE;
  1081.     }
  1082.     return erg;
  1083. }
  1084.  
  1085. /***************************************************************************/
  1086. /* Operation durchführen                                                                    */
  1087. /***************************************************************************/
  1088.  
  1089. static int e_icon_edit(int icon, int action)
  1090. {
  1091.     PATH        name = "";
  1092.     TEXTP        t_ptr = get_text(icon);
  1093.     RING        r;
  1094.     WINDOWP    window;
  1095.     int        erg;
  1096.     bool        ok, bin, shift;
  1097.     ZEILEP    lauf;
  1098.  
  1099.     shift = shift_pressed();
  1100.     window = get_window(icon);
  1101.     erg = 0;
  1102.     switch(action)
  1103.     {
  1104.         case DO_UNDO    :
  1105.             t_ptr->blk_mark_mode = FALSE;
  1106.             blk_demark(t_ptr);
  1107.             make_undo(t_ptr);
  1108.             erg = 1;
  1109.             break;
  1110.         case DO_CUT     :
  1111.             t_ptr->blk_mark_mode = FALSE;
  1112.             blk_cut(t_ptr);
  1113.             restore_edit();
  1114.             erg = 1;
  1115.             break;
  1116.         case DO_COPY    :
  1117.             t_ptr->blk_mark_mode = FALSE;
  1118.             blk_copy(t_ptr);
  1119.             restore_edit();
  1120.             erg = 1;
  1121.             break;
  1122.         case DO_LINECOPY:
  1123.             line_copy(t_ptr);
  1124.             restore_edit();
  1125.             erg = 1;
  1126.             break;
  1127.         case DO_PASTE    :
  1128.             t_ptr->blk_mark_mode = FALSE;
  1129.             load_clip();
  1130.             if (!ist_leer(&clip_text))
  1131.             {
  1132.                 blk_paste(t_ptr, &clip_text);
  1133.                 if (t_ptr->loc_opt->umbrechen && t_ptr->loc_opt->format_by_paste)
  1134.                     format(t_ptr);
  1135.                 restore_edit();
  1136.             }
  1137.             erg = 1;
  1138.             break;
  1139.         case DO_SELALL :
  1140.             t_ptr->blk_mark_mode = FALSE;
  1141.             blk_mark_all(t_ptr);
  1142.             restore_edit();
  1143.             erg = 1;
  1144.             break;
  1145.         case DO_CLOSE    :
  1146.         case DO_DELETE    :
  1147.             t_ptr->blk_mark_mode = FALSE;
  1148.             destruct(icon);
  1149.             erg = 1;
  1150.             break;
  1151.         case DO_OPEN    :
  1152.             t_ptr->blk_mark_mode = FALSE;
  1153.             if (!open_edit(icon))
  1154.                 erg = -1;
  1155.             else
  1156.                 erg = 1;
  1157.             break;
  1158.         case DO_INFO    :
  1159.             t_ptr->blk_mark_mode = FALSE;
  1160.             if (t_ptr->block)
  1161.                 block_info(t_ptr);
  1162.             else
  1163.                 info_edit(icon);
  1164.             erg = 1;
  1165.             break;
  1166.         case DO_HELP    :
  1167.             t_ptr->blk_mark_mode = FALSE;
  1168.             if (!t_ptr->block)
  1169.                 blk_mark_word(t_ptr);
  1170.             if (t_ptr->block)
  1171.             {
  1172.                 block_copy(t_ptr, &r);
  1173.                 if (strlen(TEXT(FIRST(&r))) > 0)
  1174.                     erg = call_help(TEXT(FIRST(&r)));
  1175.                 else
  1176.                     erg = call_hyp("main");
  1177.                 kill_textring(&r);
  1178.             }
  1179.             else
  1180.                 erg = call_hyp("main");
  1181.             break;
  1182.         case DO_LEFT    :
  1183.             t_ptr->blk_mark_mode = FALSE;
  1184.             blk_left(t_ptr);
  1185.             restore_edit();
  1186.             erg = 1;
  1187.             break;
  1188.         case DO_RIGHT    :
  1189.             t_ptr->blk_mark_mode = FALSE;
  1190.             blk_right(t_ptr);
  1191.             restore_edit();
  1192.             erg = 1;
  1193.             break;
  1194.         case DO_SMALL2BIG    :
  1195.             t_ptr->blk_mark_mode = FALSE;
  1196.             blk_upplow(t_ptr, BLK_UPPER);
  1197.             restore_edit();
  1198.             erg = 1;
  1199.             break;
  1200.         case DO_BIG2SMALL    :
  1201.             t_ptr->blk_mark_mode = FALSE;
  1202.             blk_upplow(t_ptr, BLK_LOWER);
  1203.             restore_edit();
  1204.             erg = 1;
  1205.             break;
  1206.         case DO_CHNG_SMBG    :
  1207.             t_ptr->blk_mark_mode = FALSE;
  1208.             blk_upplow(t_ptr, BLK_CH_UPLO);
  1209.             restore_edit();
  1210.             erg = 1;
  1211.             break;
  1212.         case DO_CAPS    :
  1213.             t_ptr->blk_mark_mode = FALSE;
  1214.             blk_upplow(t_ptr, BLK_CAPS);
  1215.             restore_edit();
  1216.             erg = 1;
  1217.             break;
  1218.         case DO_FORMAT :
  1219.             t_ptr->blk_mark_mode = FALSE;
  1220.             blk_demark(t_ptr);
  1221.             if (shift)
  1222.                 total_format(t_ptr);
  1223.             else
  1224.                 format(t_ptr);
  1225.             restore_edit();
  1226.             erg = 1;
  1227.             break;
  1228.         case DO_PRINT    :
  1229.             t_ptr->blk_mark_mode = FALSE;
  1230.             print_edit(t_ptr);
  1231.             erg = 1;
  1232.             break;
  1233.         case DO_ABAND    :
  1234. abandon:    strcpy(name, t_ptr->filename);
  1235.             bin = (t_ptr->text.ending == binmode);
  1236.             destruct(icon);
  1237.             icon = load_edit(name, bin);
  1238.             if (icon > 0)
  1239.             {
  1240.                 t_ptr = get_text(icon);
  1241.                 erg = -1;
  1242.                 if (t_ptr != NULL)
  1243.                 {
  1244.                     if (open_edit(icon))
  1245.                     {
  1246.                         memset(msgbuff, 0, (int) sizeof(msgbuff));
  1247.                         msgbuff[0] = WM_TOPPED;
  1248.                         msgbuff[3] = window->handle;
  1249.                         send_msg(gl_apid);
  1250.                         erg = 1;
  1251.                     }
  1252.                 }
  1253.             }
  1254.             clr_undo();
  1255.             break;
  1256.         case DO_SAVE    :
  1257.             if (!t_ptr->namenlos)
  1258.             {
  1259.                 t_ptr->blk_mark_mode = FALSE;
  1260.                 if (t_ptr->loc_opt->umbrechen)
  1261.                     save_absatz(t_ptr);                    /* Zeilenende korrigieren */
  1262.                 if (save(t_ptr)<0)
  1263.                     erg = -1;
  1264.                 else
  1265.                     erg = 1;
  1266.  
  1267.                 make_chg(icon, WT_CHANGE, 0);            /* nur Fenstertitel schreiben */
  1268.                 restore_edit();
  1269.                 break;
  1270.             }
  1271.             /* Bei Namenlos zu DO_SAVENEW */
  1272.         case DO_SAVENEW:
  1273.             t_ptr->blk_mark_mode = FALSE;
  1274.             if (t_ptr->block)
  1275.             {
  1276.                 strcpy(name, "");
  1277.                 if (save_new(name, "", rsc_string(SAVEBLKSTR)))
  1278.                 {
  1279.                     TEXTP temp_ptr;
  1280.  
  1281.                     temp_ptr = new_text(TEMP_LINK);
  1282.                     if (t_ptr->loc_opt->umbrechen)    /* Zeilenende korrigieren */
  1283.                         save_absatz(t_ptr);
  1284.                     block_copy(t_ptr,&temp_ptr->text);    /* Block rauskopieren */
  1285.                     temp_ptr->cursor_line = FIRST(&t_ptr->text);
  1286.                     temp_ptr->loc_opt = t_ptr->loc_opt;
  1287.                     erg = save_as(temp_ptr,name);
  1288.                     destruct_text(temp_ptr);
  1289.                     if (erg==0)
  1290.                         erg = 1;
  1291.                 }
  1292.             }
  1293.             else
  1294.             {
  1295.                 strcpy(name, t_ptr->filename);
  1296.                 if (save_new(name, "", rsc_string(SAVEASSTR)))
  1297.                 {
  1298.                     bool umb_old = t_ptr->loc_opt->umbrechen;
  1299.                     
  1300.                     if (t_ptr->loc_opt->umbrechen)    /* Zeilenende korrigieren */
  1301.                         save_absatz(t_ptr);
  1302.                     if ((erg = save_as(t_ptr, name))==0)
  1303.                     {
  1304.                         if (t_ptr->namenlos || note(1, 2, GETNAME) == 1)
  1305.                         {
  1306.                             /* OLGA informieren */
  1307.                             do_olga(OLGA_RENAME, t_ptr->filename, name);
  1308.                             do_olga(OLGA_UPDATE, name, NULL);
  1309.  
  1310.                             set_text_name(t_ptr, name, FALSE);
  1311.                             chg_edit_name(icon);
  1312.                             t_ptr->moved = 0;
  1313.                             t_ptr->file_date_time = file_time(name,NULL,NULL);
  1314.                             t_ptr->readonly = file_readonly(name);
  1315.                         }
  1316.                         make_chg(icon, TOTAL_CHANGE, 0); /* ggf. neue lok. Optionen! */
  1317.                         make_chg(icon, WT_CHANGE, 0);        /* Headline schreiben */
  1318.                         ch_kurzel(t_ptr->loc_opt->kurzel, FALSE);
  1319.                         if (umb_old != t_ptr->loc_opt->umbrechen)
  1320.                             make_absatz(t_ptr);
  1321.                         restore_edit();
  1322.                         if (erg==0)
  1323.                             erg = 1;
  1324.                     }
  1325.                 }
  1326.             }
  1327.             break;
  1328.         case DO_FIND    :
  1329.             t_ptr->blk_mark_mode = FALSE;
  1330.             if (t_ptr->block && shift_pressed())
  1331.                 find_selection(t_ptr);
  1332.             else
  1333.             {
  1334.                 if (find_erg == 1)
  1335.                 {
  1336.                     if (start_find(t_ptr,FALSE)==0)
  1337.                     {
  1338.                         Bconout(2, 7);
  1339.                         end_play();
  1340.                     }
  1341.                 }
  1342.                 else
  1343.                 {
  1344.                     if (find_erg == 2)
  1345.                     {
  1346.                         if (start_replace(t_ptr) == 0)
  1347.                         {
  1348.                             Bconout(2, 7);
  1349.                             end_play();
  1350.                         }
  1351.                     }
  1352.                 }
  1353.             }
  1354.             erg = 1;
  1355.             break;
  1356.         case DO_FINDNEXT:
  1357.             t_ptr->blk_mark_mode = FALSE;
  1358.             if (do_next(t_ptr) != 1)
  1359.             {
  1360.                     Bconout(2, 7);
  1361.                     end_play();
  1362.             }
  1363.             erg = 1;
  1364.             break;
  1365.         case DO_GOTO    :
  1366.             t_ptr->blk_mark_mode = FALSE;
  1367.             blk_demark(t_ptr);
  1368.             goto_line(t_ptr, desire_x, desire_y);
  1369.             restore_edit();
  1370.             erg = 1;
  1371.             break;
  1372.         case DO_STRIPLINES:
  1373.             t_ptr->blk_mark_mode = FALSE;
  1374.             blk_demark(t_ptr);
  1375.             graf_mouse(HOURGLASS, NULL);
  1376.             if (strip_endings(t_ptr))
  1377.             {
  1378.                 t_ptr->max_line = NULL;
  1379.                 lauf = t_ptr->cursor_line = get_line(&t_ptr->text, t_ptr->ypos);
  1380.                 if (t_ptr->xpos > lauf->len)
  1381.                     t_ptr->xpos = lauf->len;
  1382.                 make_chg(t_ptr->link, POS_CHANGE, 0);        /* '*' in Titel */
  1383.             }
  1384.             graf_mouse(ARROW, NULL);
  1385.             restore_edit();
  1386.             erg = 1;
  1387.             break;
  1388.         case DO_TAB2LZ :
  1389.             t_ptr->blk_mark_mode = FALSE;
  1390.             blk_demark(t_ptr);
  1391.             tab2lz(t_ptr);
  1392.             erg = 1;
  1393.             break;
  1394.         case DO_LZ2TAB :
  1395.             t_ptr->blk_mark_mode = FALSE;
  1396.             blk_demark(t_ptr);
  1397.             lz2tab(t_ptr);
  1398.             erg = 1;
  1399.             break;
  1400.         case DO_ADD     :
  1401.             if (shift)
  1402.                 ok = select_single(name, "", rsc_string(INSNAMESTR));
  1403.             else
  1404.                 ok = select_single(name, "", rsc_string(MERGESTR));
  1405.             if (ok)
  1406.             {
  1407.                 if (shift)                /* Dateinamen einfügen */
  1408.                 {
  1409.                     RING        temp_ring;
  1410.                     ZEILEP    col;
  1411.  
  1412.                     init_textring(&temp_ring);
  1413.                     col = new_col(name, (int)strlen(name));
  1414.                     col_insert(&(temp_ring.head), col);
  1415.                     blk_paste(t_ptr, &temp_ring);
  1416.                     restore_edit();
  1417.                     kill_textring(&temp_ring);
  1418.                 }
  1419.                 else                                /* Dateiinhalt einfügen */
  1420.                 {
  1421.                     TEXTP temp_ptr = new_text(TEMP_LINK);
  1422.                     int    antw;
  1423.                     
  1424.                     if (temp_ptr!=NULL)
  1425.                     {
  1426.                         set_text_name(temp_ptr, name, FALSE);
  1427.                         antw = load(temp_ptr, TRUE);
  1428.                         if (antw == 0)
  1429.                         {
  1430.                             if (t_ptr->loc_opt->umbrechen)
  1431.                             {
  1432.                                 temp_ptr->loc_opt = t_ptr->loc_opt;
  1433.                                 make_absatz(temp_ptr);
  1434.                                 if (temp_ptr->loc_opt->format_by_load)
  1435.                                     total_format(temp_ptr);
  1436.                             }
  1437.                             blk_paste(t_ptr,&(temp_ptr->text));
  1438.                             restore_edit();
  1439.                         }
  1440.                         else
  1441.                             open_error(name, antw);
  1442.                         destruct_text(temp_ptr);
  1443.                     }
  1444.                 }
  1445.             }
  1446.             erg = 1;
  1447.             break;
  1448.         case DO_UPDATE    :
  1449.             /* Schreibschutz oder Datei verändert? */
  1450.             if (file_exists(t_ptr->filename))
  1451.             {
  1452.                 bool    read_only = file_readonly(t_ptr->filename);
  1453.  
  1454.                 if (read_only!=t_ptr->readonly)
  1455.                 {
  1456.                     t_ptr->readonly = read_only;
  1457.                     make_chg(icon,POS_CHANGE,0);        /* Headline schreiben */
  1458.                     restore_edit();
  1459.                 }
  1460.                 if (t_ptr->file_date_time!=-1L)
  1461.                 {
  1462.                     long date_time = file_time(t_ptr->filename,NULL,NULL);
  1463.  
  1464.                     if (date_time!=t_ptr->file_date_time)
  1465.                     {
  1466.                         FILENAME    name;
  1467.  
  1468.                         file_name(t_ptr->filename, name, FALSE);
  1469.                         if (snote(1, 2, MOVED3, name) == 1)
  1470.                             goto abandon;
  1471.                         else
  1472.                             t_ptr->file_date_time = date_time;
  1473.                     }
  1474.                 }
  1475.             }
  1476.             /* Kürzel updaten */
  1477.             ch_kurzel(t_ptr->loc_opt->kurzel, FALSE);
  1478.             erg = 1;
  1479.             break;
  1480.         case DO_ZEICHTAB:
  1481.             if (ascii_wert != -1 )
  1482.                 char_insert(t_ptr, ascii_wert);
  1483.             restore_edit();
  1484.             erg = 1;
  1485.             break;
  1486.         case DO_UMLAUT:
  1487.             change_umlaute(t_ptr);
  1488.             erg = 1;
  1489.             break;
  1490.         case DO_SWAPCHAR:
  1491.             char_swap(t_ptr);
  1492.             restore_edit();
  1493.             break;
  1494.         case DO_AUTOSAVE:
  1495.             e_icon_edit(icon, DO_SAVE);
  1496.             break;
  1497.         case DO_FEHLER :
  1498.             if (error[0][0] != EOS)
  1499.             {
  1500.                 blk_demark(t_ptr);
  1501.                 restore_edit();
  1502.                 handle_error(t_ptr);
  1503.             }
  1504.             break;
  1505.         case DO_TOPLINE :
  1506.             arrow_window(window, WA_DNLINE, t_ptr->ypos - window->doc.y);
  1507.             break;
  1508.         case DO_SORT :
  1509.             sort_block(t_ptr);
  1510.             break;
  1511.     }
  1512.     return erg;
  1513. }
  1514.  
  1515. /***************************************************************************/
  1516. /* Es wurde etwas auf ein Textfenster geschoben                                        */
  1517. /***************************************************************************/
  1518.  
  1519. static bool e_icon_drag(int icon, int source)
  1520. {
  1521.     WINDOWP    w = get_window(icon);
  1522.     TEXTP     t_ptr;
  1523.     bool        ret = FALSE;
  1524.  
  1525.      if ((w->flags & WI_ICONIFIED) || (w->flags & WI_SHADED))
  1526.          return FALSE;
  1527.  
  1528.     switch (source)
  1529.     {
  1530.         case DRAGDROP_FILE :                        /* Inhalt von drag_filename einfügen */
  1531.             t_ptr = get_text(icon);
  1532.             if (drag_filename[0] != EOS && t_ptr != NULL)
  1533.             {
  1534.                 TEXTP temp_ptr = new_text(TEMP_LINK);
  1535.                 int    antw;
  1536.                 
  1537.                 if (temp_ptr!=NULL)
  1538.                 {
  1539.                     set_text_name(temp_ptr, drag_filename, FALSE);
  1540.                     antw = load(temp_ptr, TRUE);
  1541.                     if (antw == 0)
  1542.                     {
  1543.                         blk_paste(t_ptr,&(temp_ptr->text));
  1544.                         restore_edit();
  1545.                     }
  1546.                     else
  1547.                         open_error(drag_filename, antw);
  1548.                     destruct_text(temp_ptr);
  1549.                     ret = TRUE;
  1550.                 }
  1551.             }
  1552.             drag_filename[0] = EOS;
  1553.             break;
  1554.  
  1555.         case DRAGDROP_PATH :                        /* Text aus drag_filename einfügen */
  1556.             t_ptr = get_text(icon);
  1557.             if (drag_filename[0] != EOS && t_ptr != NULL)
  1558.             {
  1559.                 if ((t_ptr->cursor_line->len + (int)strlen(drag_filename)) < MAX_LINE_LEN)
  1560.                 {
  1561.                     RING        temp_ring;
  1562.                     ZEILEP    col;
  1563.                         
  1564.                     init_textring(&temp_ring);
  1565.                     col = new_col(drag_filename, (int)strlen(drag_filename));
  1566.                     col_insert(&(temp_ring.head), col);
  1567.                     if (drag_data_size > 1)
  1568.                     {
  1569.                         /* mehr als ein ARGS -> Zeilenvorschub */
  1570.                         col = new_col("", 0);
  1571.                         col_append(&temp_ring, col);
  1572.                     }
  1573.                     blk_paste(t_ptr, &temp_ring);
  1574.                     restore_edit();
  1575.                     kill_textring(&temp_ring);
  1576.                     ret = TRUE;
  1577.                 }
  1578.                 else
  1579.                     inote(1, 0, TOOLONG, MAX_LINE_LEN);
  1580.             }
  1581.             drag_filename[0] = EOS;
  1582.             break;
  1583.  
  1584.         case DRAGDROP_DATA :                        /* Textdaten einfügen */
  1585.             if (drag_data_size > 0 && drag_data != NULL)
  1586.             {
  1587.                 RING        temp_ring;
  1588.                 ZEILEP    col;
  1589.                 char        *p1, *p2, *zeile;
  1590.                 long        delta;
  1591.                 ZEILEP    lauf;
  1592.  
  1593.                 t_ptr = get_text(icon);
  1594.                 init_textring(&temp_ring);
  1595.                 lauf = &temp_ring.head;
  1596.                 p1 = drag_data;
  1597.                 p2 = strchr(p1, '\r');
  1598.                 if (p2 != NULL)                            /* mehrere Zeilen? */
  1599.                 {
  1600.                     zeile = (char *) malloc(MAX_LINE_LEN);
  1601.                     while (p2 != NULL)
  1602.                     {
  1603.                         delta = p2 - p1;
  1604.                         strncpy(zeile, p1, delta);
  1605.                         zeile[delta] = EOS;
  1606.                         col = new_col(zeile, (int)strlen(zeile));
  1607.                         col_insert(lauf, col);
  1608.                         NEXT(lauf);
  1609.                         p1 = p2 + 2;                        /* \r\n überspringen */
  1610.                         p2 = strchr(p1, '\r');
  1611.                         temp_ring.lines++;
  1612.                     }
  1613.                     free(zeile);
  1614.                 }
  1615.                 else                                            /* nur eine Zeile ohne \r\n */
  1616.                 {
  1617.                     col = new_col(drag_data, (int)strlen(drag_data));
  1618.                     col_insert(lauf, col);
  1619.                 }
  1620.                 blk_paste(t_ptr, &temp_ring);
  1621.                 restore_edit();
  1622.                 kill_textring(&temp_ring);
  1623.                 free(drag_data);                            /* Speicher wieder freigeben */
  1624.                 drag_data_size = 0L;
  1625.                 ret = TRUE;
  1626.             }
  1627.             break;
  1628.  
  1629.         default:
  1630.             if (debug_level)
  1631.                 debug("edit.e_icon_drag(): Unbekannter Mode %d\n", source);
  1632.     }
  1633.  
  1634.     return ret;
  1635. }
  1636.  
  1637. /***************************************************************************/
  1638.  
  1639. void blink_edit(void)
  1640. {
  1641.     WINDOWP    window;
  1642.     TEXTP     t_ptr;
  1643.  
  1644.     window = winlist_top();
  1645.     if (window!=NULL && window->class==CLASS_EDIT)
  1646.     {
  1647.         t_ptr = get_text(window->handle);
  1648.         if (t_ptr->cursor)
  1649.         {
  1650.             if (t_ptr->blink)         /* gerade wg. Blinken aus */
  1651.                 t_ptr->blink = FALSE;
  1652.             else
  1653.                 t_ptr->blink = TRUE;
  1654.             cursor(window,t_ptr);
  1655.         }
  1656.     }
  1657. }
  1658.  
  1659. void onblink_edit(void)
  1660. {
  1661.     WINDOWP    window;
  1662.     TEXTP     t_ptr;
  1663.  
  1664.     window = winlist_top();
  1665.     if (window!=NULL && window->class==CLASS_EDIT)
  1666.     {
  1667.         t_ptr = get_text(window->handle);
  1668.         if (t_ptr->cursor)
  1669.         {
  1670.             cursor(window,t_ptr);
  1671.             t_ptr->blink = FALSE;
  1672.         }
  1673.     }
  1674. }
  1675.  
  1676. void offblink_edit(void)
  1677. {
  1678.     WINDOWP    window;
  1679.     TEXTP     t_ptr;
  1680.  
  1681.     window = winlist_top();
  1682.     if (window!=NULL && window->class==CLASS_EDIT)
  1683.     {
  1684.         t_ptr = get_text(window->handle);
  1685.         if (t_ptr->cursor && !t_ptr->blink)
  1686.         {
  1687.             cursor(window,t_ptr);
  1688.         }
  1689.     }
  1690. }
  1691.  
  1692. /***************************************************************************/
  1693. /* Tastenverarbeitung                                                                        */
  1694. /***************************************************************************/
  1695. void make_chg (int link, int change, long ypos)
  1696. {
  1697. /*
  1698.     SCROLL_UP         Alles unter der aktuellen Zeile wird hochgescrollt,
  1699.                         die letzte Zeile wird natürlich neu geschrieben.
  1700.                           (Cntrl-Y, und Delete am Ende der Zeile).
  1701.     SCROLL_DOWN        Alles unterhalb der aktuellen Zeile und diese Zeile werden
  1702.                         nach unten gescrollt, die aktuelle Zeile wird neu
  1703.                         geschrieben. Ist auch LINE_CHANGE gesetzt wird auch die
  1704.                         Zeile vor der aktuellen Zeile neu geschrieben.
  1705.                         (RETURN, last_out_klemm)
  1706.     MOVE_UP,
  1707.     MOVE_DOWN        Das Fenster wird hoch und runter gescrollt um anz Zeilen
  1708.     BLK_CHANGE        Die Blockmarkierung wurde geändert.
  1709.     WT_CHANGE        Fenstertitel ('*') löschen (nach save).
  1710. */
  1711.     int i;
  1712.  
  1713.     if (change==TOTAL_CHANGE)
  1714.     {
  1715.         for (i=chg_anz; (--i)>=0; )            /* unnützte Änderung */
  1716.             if (chg[i].link==link)
  1717.             {
  1718.                 if (chg[i].c==LINE_CHANGE && chg[i].y>=ypos)
  1719.                     chg[i].c = NOP_CHANGE;
  1720.                 else if (chg[i].c==SCROLL_DOWN && chg[i].y>=ypos)
  1721.                     chg[i].c = NOP_CHANGE;
  1722.                 else if (chg[i].c==SCROLL_UP && chg[i].y>=ypos)
  1723.                     chg[i].c = NOP_CHANGE;
  1724.                 else if (chg[i].c==TOTAL_CHANGE && chg[i].y>=ypos)
  1725.                 {
  1726.                     chg[i].y = ypos;
  1727.                     break;
  1728.                 }
  1729.             }
  1730.     }
  1731.     if (change==LINE_CHANGE)
  1732.     {
  1733.         for (i=chg_anz; (--i)>=0; )            /* gleiche Änderung */
  1734.             if (chg[i].link==link && chg[i].c==change && chg[i].y==ypos)
  1735.                 return;
  1736.     }
  1737.     if (change==POS_CHANGE)
  1738.     {
  1739.         for (i=chg_anz; (--i)>=0; )
  1740.             if (chg[i].link==link && chg[i].c==change)
  1741.                 return;
  1742.     }
  1743.     if (chg_anz>=MAX_CHG)
  1744.     {
  1745.         inote(1, 0, FATALERR,0);
  1746.         return;
  1747.     }
  1748.     chg[chg_anz].link = link;
  1749.     chg[chg_anz].c = change;
  1750.     chg[chg_anz].y = ypos;
  1751.     setincl(chg_links,link);
  1752.     chg_anz++;
  1753. }
  1754.  
  1755. void pos_korr(WINDOWP window, TEXTP t_ptr)
  1756. {
  1757.     int    x_new;
  1758.     long    y_new;
  1759.  
  1760.     y_new = t_ptr->ypos - window->doc.y;
  1761.     if (y_new < 0L)
  1762.     {
  1763.         if (y_new == -1L)
  1764.             arrow_window(window, WA_UPLINE, 1);
  1765.         else
  1766.             arrow_window(window, WA_UPLINE, window->w_height/2-y_new);
  1767.     }
  1768.     else if (y_new >= window->w_height)
  1769.     {
  1770.         if (y_new == window->w_height)
  1771.             arrow_window(window, WA_DNLINE, 1);
  1772.         else
  1773.             arrow_window(window, WA_DNLINE, y_new-window->w_height/2);
  1774.     }
  1775.  
  1776.     x_new = cursor_xpos(t_ptr, t_ptr->xpos) - (int) window->doc.x * font_wcell;
  1777.     if (x_new < 0)
  1778.         arrow_window(window, WA_LFLINE, -(x_new/font_wcell) + window->w_width/2);
  1779.     else if (x_new >= window->work.g_w)
  1780.         arrow_window(window, WA_RTLINE, (x_new-window->work.g_w)/font_wcell + window->w_width/2);
  1781. }
  1782.  
  1783. /*
  1784.  * Neuzeichnen, wenn Fenster teilweise verdeckt.
  1785.  * z.B. bei D&D
  1786. */
  1787. static void restore_offdesk(WINDOWP window, TCHANGE *c, int c_anz, TEXTP t_ptr)
  1788. {
  1789.     int        y_screen;
  1790.     bool    done = FALSE;
  1791.     GRECT        a;
  1792.  
  1793.     for (; (--c_anz)>=0; c++)
  1794.     {
  1795.         switch (c->c)
  1796.         {
  1797.             case WT_CHANGE :    /* für save(): nur '*' löschen, sonst nix */
  1798.                 change_window(window, t_ptr->filename, (t_ptr->moved!=0));
  1799.                 break;
  1800.  
  1801.             case POS_CHANGE     :
  1802.                 if (window->class==CLASS_EDIT)
  1803.                 {
  1804.                     a = window->work;
  1805.                     a.g_h = gl_hchar;
  1806.                     redraw_window(window, &a);
  1807.                 }
  1808.                 change_window(window, t_ptr->filename, (t_ptr->moved!=0));
  1809.                 pos_korr(window, t_ptr);
  1810.                 break;
  1811.  
  1812.             case LINE_CHANGE:
  1813.                 y_screen = (int) (c->y - window->doc.y);
  1814.                 if (y_screen>=0 && y_screen<window->w_height)
  1815.                 {
  1816.                     a = window->work;
  1817.                     a.g_y += y_screen * window->yfac;
  1818.                     a.g_h = window->yfac;
  1819.                     redraw_window(window, &a);
  1820.                 }
  1821.                 break;
  1822.  
  1823.             case TOTAL_CHANGE  :
  1824.             case BLK_CHANGE     :
  1825.             case SCROLL_UP      :
  1826.             case SCROLL_DOWN :
  1827.                 if (!done)
  1828.                     redraw_window(window, &window->work);
  1829.                 done = TRUE;
  1830.                 break;
  1831.  
  1832.             case MOVE_UP:
  1833.                 arrow_window(window, WA_DNLINE, c->y);
  1834.                 break;
  1835.  
  1836.             case MOVE_DOWN:
  1837.                 arrow_window(window, WA_UPLINE, c->y);
  1838.                 break;
  1839.         }
  1840.     }
  1841. }
  1842.  
  1843. /*
  1844.  * Neuzeichnen, wenn Fenster komplett frei.
  1845. */
  1846. static void restore_indesk(WINDOWP window, TCHANGE *c, int c_anz, TEXTP t_ptr)
  1847. {
  1848.     GRECT    a;
  1849.     int    y_screen, help;
  1850.     long    z1,z2;
  1851.  
  1852.     for (; (--c_anz)>=0; c++)
  1853.     {
  1854.         set_clip(TRUE, &(window->work));
  1855.         switch (c->c)
  1856.         {
  1857.             case WT_CHANGE:                /* nur '*' ändern, sonst nix */
  1858.                 change_window(window, t_ptr->filename, (t_ptr->moved!=0));
  1859.                 break;
  1860.  
  1861.             case POS_CHANGE:
  1862.                 if (window->class == CLASS_EDIT)
  1863.                     head_out(window, t_ptr);
  1864.                 change_window(window, t_ptr->filename, (t_ptr->moved!=0));
  1865.                 pos_korr(window, t_ptr);
  1866.                 break;
  1867.  
  1868.             case LINE_CHANGE:
  1869.                 y_screen = (int)(c->y - window->doc.y);
  1870.                 if (y_screen < window->w_height)
  1871.                     line_out(window, t_ptr, y_screen);
  1872.                 break;
  1873.  
  1874.             case TOTAL_CHANGE:
  1875.                 y_screen = (int) (c->y - window->doc.y);
  1876.                 bild_out(window,t_ptr);
  1877.                 break;
  1878.  
  1879.             case SCROLL_UP:
  1880.                 y_screen = (int) (c->y - window->doc.y);
  1881.                 if (y_screen < window->w_height-1)
  1882.                 {
  1883.                     help = window->yfac*(y_screen+1);
  1884.                     a = window->work;
  1885.                     a.g_h -= help;
  1886.                     a.g_y += help;
  1887.                     scroll_vertical (&a, window->yfac);
  1888.                 }
  1889.                 if (y_screen < window->w_height)
  1890.                     line_out(window, t_ptr, window->w_height-1);
  1891.                 break;
  1892.  
  1893.             case SCROLL_DOWN:
  1894.                 y_screen = (int) (c->y - window->doc.y);
  1895.                 if (y_screen < window->w_height-1)
  1896.                 {
  1897.                     a = window->work;
  1898.                     a.g_h -= window->yfac * (y_screen + 1);
  1899.                     a.g_y += window->yfac * y_screen;
  1900.                     scroll_vertical (&a, -window->yfac);
  1901.                 }
  1902.                 /* Die neue Zeile wird mit LINE_CHANGE gezeichnet */
  1903.                 break;
  1904.  
  1905.             case MOVE_UP:
  1906.                 arrow_window(window, WA_DNLINE, c->y);
  1907.                 break;
  1908.  
  1909.             case MOVE_DOWN:
  1910.                 arrow_window(window, WA_UPLINE, c->y);
  1911.                 break;
  1912.  
  1913.             case BLK_CHANGE:
  1914.                 z1 = c->y;
  1915.                 c++; c_anz--;
  1916.                 z2 = c->y;
  1917.                 bild_blkout(window,t_ptr,z1,z2);
  1918.                 break;
  1919.         }
  1920.     }
  1921. }
  1922.  
  1923. void restore_edit(void)
  1924. {
  1925.     WINDOWP    window;
  1926.     TEXTP     t_ptr;
  1927.     int        i, c_anz, link, max;
  1928.     TCHANGE    c[MAX_CHG], *c_ptr;
  1929.     
  1930.     if (!chg_anz) 
  1931.         return;
  1932.  
  1933.     hide_mouse();
  1934.     max = setmax(chg_links);
  1935.     for (link = setmin(chg_links); link <= max; link++) 
  1936.     {
  1937.         if(setin(chg_links,link))
  1938.         {
  1939.             window = get_window(link);
  1940.             if (window == NULL) 
  1941.                 continue;                                /* Kommt vor (Prj_Text mit 10001) */
  1942.             c_anz = 0;
  1943.             c_ptr = chg;
  1944.             for (i=chg_anz; (--i)>=0; c_ptr++)
  1945.                 if (c_ptr->link==link && c_ptr->c!=NOP_CHANGE)
  1946.                     c[c_anz++] = *c_ptr;
  1947.     
  1948.             t_ptr = get_text(window->handle);
  1949.  
  1950.             /* Slider anpassen */
  1951.             if (window->doc.h != t_ptr->text.lines)
  1952.             {
  1953.                 window->doc.h = t_ptr->text.lines;
  1954.                 set_sliders(window, VERTICAL, SLPOS+SLSIZE);
  1955.             }
  1956.  
  1957.             get_longestline(t_ptr);
  1958.             if (window->doc.w != t_ptr->max_line->exp_len)
  1959.             {
  1960.                 window->doc.w = t_ptr->max_line->exp_len;
  1961.                 set_sliders(window, HORIZONTAL, SLPOS+SLSIZE);
  1962.             }    
  1963.  
  1964.             if ((window->flags & WI_OPEN) || (window->flags & WI_ICONIFIED))
  1965.             {
  1966.                 if (free_for_draw(window))
  1967.                     restore_indesk(window, c, c_anz, t_ptr);
  1968.                 else
  1969.                     restore_offdesk(window, c, c_anz, t_ptr);
  1970.             }
  1971.         }
  1972.     }
  1973.     show_mouse();
  1974.     chg_anz = 0;            /* Keine Änderungen mehr */
  1975.     setclr(chg_links);
  1976. }
  1977.  
  1978. /***************************************************************************/
  1979. static void destruct(int icon)
  1980. {
  1981.     TEXTP t_ptr = get_text(icon);
  1982.     WINDOWP window = get_window(icon);
  1983.  
  1984.     insert_poslist(&lastpos_list, t_ptr->filename, t_ptr->xpos, t_ptr->ypos);
  1985.  
  1986.     /* Text war Error-Datei */
  1987.     if (t_ptr == last_errtext)
  1988.         last_errtext = NULL;
  1989.  
  1990.     close_window(window);
  1991.     destruct_text(t_ptr);
  1992.     del_icon(icon);
  1993.     setexcl(used_info,icon);
  1994.     clr_undo();
  1995.     do_all_icon(prj_type, DO_UPDATE);        /* Projekte updaten */
  1996. }
  1997.  
  1998. /***************************************************************************/
  1999.  
  2000. static int crt_new_text(char *filename, bool bin)
  2001. {
  2002.     TEXTP         t_ptr;
  2003.     WINDOWP        win;
  2004.     PATH            name;
  2005.     bool        namenlos;
  2006.  
  2007.     if (filename[0] == EOS)
  2008.     {
  2009.         strcpy(name, rsc_string(NAMENLOS));
  2010.         namenlos = TRUE;
  2011.     }
  2012.     else
  2013.     {
  2014.         strcpy(name, filename);
  2015.         namenlos = FALSE;
  2016.     }
  2017.     
  2018.     /* Fenster anlegen */
  2019.     win = create_window(KIND, CLASS_EDIT, crt_edit);
  2020.     if (win == NULL)
  2021.         return -1;
  2022.     if (!add_icon(edit_type, win->handle))
  2023.         return -1;
  2024.  
  2025.     /* Text kreiern */
  2026.     t_ptr = new_text(win->handle);
  2027.     if (t_ptr == NULL)
  2028.     {
  2029.         del_icon(win->handle);
  2030.         return -1;
  2031.     }
  2032.  
  2033.     if (bin)
  2034.     {
  2035.         t_ptr->text.ending = binmode;
  2036.         t_ptr->text.max_line_len = bin_line_len;
  2037.     }
  2038.     else
  2039.         t_ptr->text.max_line_len = MAX_LINE_LEN;
  2040.  
  2041.     set_text_name(t_ptr, name, namenlos);
  2042.     setincl(used_info, win->handle);
  2043.  
  2044.     set_wtitle(win, name);
  2045.     set_winfo(win, "");
  2046.     
  2047.     if (!namenlos)
  2048.         do_all_icon(prj_type, DO_UPDATE);                /* Projekte updaten */
  2049.  
  2050.     t_ptr->asave = time(NULL);
  2051.  
  2052.     return win->handle;
  2053. }
  2054.  
  2055. /***************************************************************************/
  2056. /* Kreieren eines Fensters                                                                 */
  2057. /***************************************************************************/
  2058. static void crt_edit(WINDOWP window)
  2059. {
  2060.     int        initw, inith;
  2061.  
  2062.     if (window->work.g_w == 0 || window->work.g_h == 0)
  2063.     {
  2064.         /* Keine Größe bekannt. */
  2065.         initw  = min ((gl_desk.g_w / font_wcell) * font_wcell - 7 * font_wcell, 80 * font_wcell);
  2066.         inith  = (gl_desk.g_h / font_hcell) * font_hcell - 7 * font_hcell;
  2067.     
  2068.         window->work.g_x    = gl_wchar + 2 * 8;
  2069.         window->work.g_y    = 60;
  2070.         window->work.g_w    = initw;
  2071.         window->work.g_h    = inith;
  2072.     }
  2073.     
  2074.     window->flags        = FLAGS;
  2075.     window->doc.w        = 0;
  2076.     window->doc.h        = 0;
  2077.     window->xfac        = font_wcell;
  2078.     window->yfac        = font_hcell;
  2079.     window->w_width    = initw/font_wcell;
  2080.     window->w_height    = inith/font_hcell;
  2081.     window->draw        = wi_draw;
  2082.     window->click        = wi_click;
  2083.     window->key         = wi_key;
  2084.     window->top            = wi_top;
  2085.     window->ontop        = wi_top;
  2086.     window->iconify    = wi_iconify;
  2087.     window->uniconify    = wi_uniconify;
  2088.     window->close        = NULL;
  2089. }
  2090.  
  2091. /***************************************************************************/
  2092. /* Öffnen des Objekts                                                                        */
  2093. /***************************************************************************/
  2094. static bool open_edit(int icon)
  2095. {
  2096.     bool    ok;
  2097.     WINDOWP    window = get_window(icon);
  2098.  
  2099.     ok = TRUE;
  2100.  
  2101.     if (window->flags & WI_ICONIFIED)
  2102.         uniconify_window(window, NULL);
  2103.     else if (window->flags & WI_SHADED)
  2104.         shade_window(window, -1);
  2105.     else if (window->flags & WI_OPEN)
  2106.         top_window(window);
  2107.     else
  2108.     {
  2109.         TEXTP t_ptr = get_text(window->handle);
  2110.  
  2111.         window->doc.x = 0;
  2112.         window->doc.y = 0;
  2113.         window->doc.h = t_ptr->text.lines;
  2114.         pos_korr(window, t_ptr);
  2115.         ok = open_window (window);
  2116.         ch_kurzel(t_ptr->loc_opt->kurzel, FALSE);
  2117.     }
  2118.     return ok;
  2119. }
  2120.  
  2121. /***************************************************************************/
  2122. /* Info des Objekts                                                                            */
  2123. /***************************************************************************/
  2124. bool info_edit (int icon)
  2125. {
  2126.     char            str[32], date[11];
  2127.     TEXTP         t_ptr = get_text(icon);
  2128.     int            erg;
  2129.     LINEENDING    ending;
  2130.     bool            b;
  2131.     
  2132.     set_long(textinfo, INFBYTES, textring_bytes(&t_ptr->text));
  2133.     if (t_ptr->text.ending != binmode)
  2134.         set_long(textinfo, INFZEILE, t_ptr->text.lines);
  2135.     else
  2136.         set_string(textinfo, INFZEILE, "--");        /* Binär: keine Zeilen */
  2137.  
  2138.     make_shortpath(t_ptr->filename, str, 30);
  2139.     set_string (textinfo, INFNAME, str);        /* Name mit Pfad */
  2140.     if (t_ptr->namenlos)
  2141.     {
  2142.         strcpy(str, "");
  2143.         strcpy(date, "--");
  2144.     }
  2145.     else
  2146.         file_time (t_ptr->filename, date, str);
  2147.     set_string(textinfo, INFDATUM, date);     /* Datum */
  2148.     set_string(textinfo, INFZEIT, str);        /* Uhrzeit */
  2149.  
  2150.     set_state(textinfo, INFTOS, SELECTED, (t_ptr->text.ending == tos));
  2151.     set_state(textinfo, INFUNIX, SELECTED, (t_ptr->text.ending == unix));
  2152.     set_state(textinfo, INFMAC, SELECTED, (t_ptr->text.ending == apple));
  2153.     ending = t_ptr->text.ending;
  2154.  
  2155.     /* Dateien aus einem Projekt oder Binär -> kein Zeilenende */
  2156.     b = (!setin(used_info, icon) || (t_ptr->text.ending == binmode));
  2157.     set_state(textinfo, INFTOS, DISABLED, b);
  2158.     set_state(textinfo, INFUNIX, DISABLED, b);
  2159.     set_state(textinfo, INFMAC, DISABLED, b);
  2160.  
  2161.     erg = simple_mdial(textinfo, 0) & 0x7fff;
  2162.     if (erg == INFOK)
  2163.     {
  2164.         if (get_state(textinfo, INFTOS, SELECTED))
  2165.             t_ptr->text.ending = tos;
  2166.         if (get_state(textinfo, INFUNIX, SELECTED))
  2167.             t_ptr->text.ending = unix;
  2168.         if (get_state(textinfo, INFMAC, SELECTED))
  2169.             t_ptr->text.ending = apple;
  2170.  
  2171.         if (t_ptr->text.ending != ending)
  2172.         {
  2173.             t_ptr->moved++;
  2174.             make_chg(t_ptr->link, POS_CHANGE, 0);     /* Damit Infozeile einen '*' bekommt */
  2175.             restore_edit();
  2176.         }
  2177.     }
  2178.     return TRUE;
  2179. }
  2180.  
  2181. void init_edit(void)
  2182. {
  2183.     setclr(chg_links);
  2184.     setclr(used_info);
  2185.     drag_filename[0] = EOS;
  2186.     edit_type = decl_icon_type(e_icon_test, e_icon_edit, e_icon_exist, e_icon_drag);
  2187. }
  2188.  
  2189. void    cursor_off(int wHandle)
  2190. {
  2191.     WINDOWP    window;
  2192.     TEXTP     t_ptr;
  2193.  
  2194.     window = get_window(wHandle);
  2195.     if (window!=NULL && window->class==CLASS_EDIT)
  2196.     {
  2197.         t_ptr = get_text(window->handle);
  2198.         if (t_ptr->cursor)
  2199.             t_ptr->cursor = FALSE;
  2200.     }
  2201. }
  2202.  
  2203. void    cursor_on(int wHandle)
  2204. {
  2205.     WINDOWP    window;
  2206.     TEXTP     t_ptr;
  2207.  
  2208.     window = get_window(wHandle);
  2209.     if (window!=NULL && window->class==CLASS_EDIT)
  2210.     {
  2211.         t_ptr = get_text(window->handle);
  2212.         if (!t_ptr->cursor)
  2213.             t_ptr->cursor = TRUE;
  2214.     }
  2215. }
  2216.  
  2217. void set_info(TEXTP t_ptr, char *str)
  2218. {
  2219.     strcpy(t_ptr->info_str, str);
  2220. }
  2221.  
  2222. void clear_info(TEXTP t_ptr)
  2223. {
  2224.     if (t_ptr->info_str[0] != EOS)
  2225.         strcpy(t_ptr->info_str, "");
  2226. }
  2227.  
  2228. /***************************************************************************/
  2229. static void do_color_change(WINDOWP w)
  2230. {
  2231.     redraw_window(w, &w->work);
  2232. }
  2233.  
  2234. void color_change(void)
  2235. {
  2236.     vsf_color(vdi_handle, bg_color);
  2237.     vst_color(vdi_handle, fg_color);
  2238.     fill_color = bg_color;
  2239.     
  2240.     /* Alle Fenster updaten */
  2241.     do_all_window(CLASS_ALL, do_color_change);
  2242. }
  2243.